﻿@{
    Layout = null;
}

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>盘点差异</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/select2/select2.min.js"></script>
    <link href="~/Content/select2/select2.min.css" rel="stylesheet" />
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script type="text/html" id="barDemo">
        <a title="明细" href="javascript:;" lay-event="dList"><i class="layui-icon">&#xe63c;</i></a>


    </script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">

                    <div class="layui-card-header">
                        <button class="layui-btn" id="barAdd" type="button" onclick="cData()" style="margin-top:10px"><i class="layui-icon"></i>差异处理</button>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>

                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    var pchCode = "0"
    var barType = "0";
    var types = "";
    $(function () {
        pchCode = getUrlVariable("pchCode");
        barType = getUrlVariable("barType");//Bar 条码 
        types = getUrlVariable("types");//0 1 亏 盈
        loadData();
    });
    function loadData() {

        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
                , url: "../ProCheck/GetDataList?condition=" + pchCode + "&dataType=diff&limit=" + barType + "&typesCode=" + types
                , skin: 'row' //表格风格
                , even: true
                , page: false //是否显示分页

                , cols: [[ //标题栏
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'barCode', align: 'center', title: '条码编码', width: '25%' }
                    , { field: 'number', align: 'center', title: '数量', width: '20%' }
                    , { field: 'done', align: 'center', title: '数据状态', width: '20%' }
                    , { field: 'memo', align: 'center', title: '备注', width: '30%' }
                    , { field: 'id', title: 'id', width: 80 }
                ]], done: function (res, curr, count) {
                    $("[data-field='id']").css('display', 'none');//隐藏列
                }
            });
        });
    }
    function cData() {
        layer.confirm('确认要处理选中差异数据？', function (index) {
            var etype = "";
            if (types == "1") {
                etype = "0";
            } else {
                etype = "1";
            }
            let table = layui.table
            let checkStatus = table.checkStatus('list'),
                data = checkStatus.data;
            var vCodes = "";
            for (var i = 0; i < data.length; i++) {
                if (data[i]["done"] != "未处理") {
                    layer.msg("已处理：" + data[i]["barCode"]);
                    vCodes = "";
                    return;
                } else {
                    vCodes += data[i]["id"] + ",";
                }
            }
            if (vCodes != "") {
                vCodes = vCodes.substring(0, vCodes.length - 1);
                $.ajax({
                    url: '../ProCheck/DoCheckDiffer',
                    data: { ids: vCodes, barType: barType, enType: etype },
                    dataType: "json",
                    type: "POST",
                    async: false,
                    success: function (data) {

                        if (data.Result) {
                            layer.msg("操作成功");
                            loadData();
                        } else {
                            layer.msg(info.Message);
                        }
                    }
                });
            } else {
                layer.msg("请先选择数据！");
            }


            layer.close(index);
        });

    }
</script>
